<template>
  <navbar>
    <img @click="back" class="back" slot="left" src="~assets/img/common/back.svg" alt />
    <div class="top-navbar" slot="center">
      <div
        v-for="(item,index) in title"
        :key="item"
        class="top-navbar-item"
        :class="{ active:currentIndex === index }"
        @click="titleClick(index)"
      >{{ item }}</div>
    </div>
  </navbar>
</template>

<script>
import navbar from "components/common/navbar/navbar";
export default {
  name: "TopNavBar",
  data() {
    return {
      title: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0
    };
  },
  components: {
    navbar
  },
  methods: {
    back() {
      this.$router.back();
    },
    titleClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    }
  }
};
</script>

<style lang="less" scoped>
.back {
  padding-top: 10px;
}
.top-navbar {
  display: flex;
  font-size: 14px;
  .top-navbar-item {
    flex: 1;
    &.active {
      color: var(--color-high-text);
    }
  }
}
</style>